﻿<Window x:Class="SharePoint.Security.ContentScanner.Client.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Sharepoint Content Scanner" Height="800" Width="1500"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:local="clr-namespace:SharePoint.Security.ContentScanner.Engine.Analyzers;assembly=SharePoint.Security.ContentScanner.EngineBasic">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
    </Window.Resources>
    <xctk:BusyIndicator Name="ProgressIndicator" IsBusy="False" BusyContent="Please wait..." >
        <Grid Background="White" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width=".40*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="48" />
                <RowDefinition Height="10" />
                <RowDefinition Height="*" />
                <RowDefinition Height=".1*"  />

            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
                <Grid Background="#60A917" Grid.Row="0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
                        <TextBlock Padding="10,10,0,10" Text="SharePoint Content Scanner" FontSize="20" Foreground="White" Grid.Column="0"></TextBlock>
                        <TextBlock Padding="4,10,10,10" Text="Basic" FontSize="12" Foreground="White" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
                    </StackPanel>
                </Grid>
            </StackPanel>
            <ScrollViewer Grid.Row="1" Grid.Column="0" Grid.RowSpan="3">
                <StackPanel Orientation="Vertical"  Background="LightGray"  
                        ScrollViewer.VerticalScrollBarVisibility="Visible"
                         >
                    <TextBlock Text="Scan Settings" Margin="10"
                       FontSize="25" Foreground="Black" TextTrimming="None" 
                       TextWrapping="WrapWithOverflow"                        />

                    <Expander Name="ExpanderDeploymentType" Margin="10,0,0,10" Header="Deployment Type" FontSize="14" Expanded="Expander_OnExpanded">
                        <StackPanel>
                            <TextBlock Text="Tool supports on premise SharePoint scan as well as SharePoint online scan. Please select appropriate type." 
                       TextTrimming="None" Margin="10,10,10,10"
                       TextWrapping="WrapWithOverflow" 
                       />
                            <ComboBox Name="CboType" Margin="10,0,10,10" SelectedValuePath="Content" >
                                <ComboBoxItem Content="Online" Tag="Online" IsSelected="True" />
                                <ComboBoxItem Content="OnPremise" Tag="OnPremise" IsSelected="False"/>
                            </ComboBox>                                                    
                        </StackPanel>
                    </Expander>

                    <Expander Margin="10,0,0,10" Name="ExpanderSiteCollection" Header="Site Collections" FontSize="14" Expanded="Expander_OnExpanded">
                        <StackPanel>

                            <TextBlock Text="Add site collection for processing. You can either enter the URL or browse input file containing list of URls." 
                      TextTrimming="None" Margin="10,10,10,10"
                       TextWrapping="WrapWithOverflow" 
                       />

                            <CheckBox Name="ChkProcessSubSites" Content="Process sub sites"
                                      Margin="10,0,0,0" FontSize="14"></CheckBox>
                            <StackPanel Orientation="Horizontal">
                                <RadioButton Name="RdUrlFromTxt"  Margin="10,10,0,20" Content="URL"  Checked="ToggleButton_OnChecked"></RadioButton>
                                <RadioButton Name="RdUrlFromFile" Margin="10,10,0,10" Content="URLs from file" Checked="ToggleButton_OnChecked"></RadioButton>

                            </StackPanel>


                            <StackPanel Name="PanelUrlFromText" Margin="10,0,0,0">

                                <TextBox Name="TxtUrl" FontSize="14" Height="30" Margin="10,0,10,10" 
                                     VerticalContentAlignment="Center"
                         HorizontalAlignment="Stretch" BorderThickness="0" Grid.Column="0"/>
                            </StackPanel>

                            <Grid Margin="10,0,0,10" Name="PanelUrlFromFile" Visibility="Collapsed">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width=".20*"/>
                                </Grid.ColumnDefinitions>

                                <TextBox Name="TxtUrlFromFile" FontSize="14" Height="30" Margin="10,0,2,5" 
                                         VerticalContentAlignment="Center"
                         HorizontalAlignment="Stretch" BorderThickness="0" Grid.Column="0"/>
                                <Button VerticalAlignment="Center" Name="BtnBrowse" 
                    Content="Browse" Height="32" Width="50" Margin="3,-5,10,0"
                        Click="BtnBrowse_OnClick" HorizontalAlignment="Right" Grid.Column="1" />

                            </Grid>
                            <StackPanel Orientation="Horizontal">


                            </StackPanel>

                            <StackPanel Name="stkUserCredentials" Orientation="Vertical">
                                <StackPanel.Style>
                                    <Style TargetType="StackPanel">
                                        <Setter Property="Visibility" Value="Collapsed"></Setter>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding ElementName=CboType, Path=SelectedItem.Tag}" Value="OnPremise">
                                                <Setter Property="Visibility"  Value="Visible"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </StackPanel.Style>
                                <CheckBox Name="chkUserCredentials" Content="Provide Credentials" Margin="10,0,10,0" FontSize="14" Unchecked="chkUserCredentials_Unchecked" ></CheckBox>
                                <Grid Name="PanelUserCredentials" Visibility="{Binding Path=IsChecked, ElementName=chkUserCredentials, Converter={StaticResource BoolToVisConverter}}" >
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Name="TxtBlkUserName" Text="Username" FontSize="14" Height="30" Margin="10,0,2,5" Grid.Column="0" Grid.Row="0" TextAlignment="Center" VerticalAlignment="Top" HorizontalAlignment="Stretch" ></TextBlock>
                                    <TextBlock Name="TxtBlkPassword" Text="Password" FontSize="14" Height="30" Margin="10,0,2,5" Grid.Column="0" Grid.Row="2"  TextAlignment="Center" HorizontalAlignment="Stretch"   ></TextBlock>
                                    <TextBox Name="TxtUserName" FontSize="14" Height="30" Margin="10,0,2,5" Grid.Column="1" Grid.Row="0"  HorizontalAlignment="Stretch" VerticalContentAlignment="Center" BorderThickness="0" ></TextBox>
                                    <PasswordBox Name="TxtPassword" FontSize="14" Height="30" Margin="10,0,2,5" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Stretch" VerticalContentAlignment="Center" BorderThickness="0"></PasswordBox>
                                    <!--<Grid.Style>
                                        <Style TargetType="Grid">
                                            <Setter Property="Visibility" Value="Collapsed"></Setter>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding ElementName=chkUserCredentials, Path=SelectedItem.Tag}" Value="OnPremise">
                                                    <Setter Property="Visibility"  Value="Visible"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Grid.Style>-->
                                </Grid>
                            </StackPanel>

                            <Button VerticalAlignment="Center" Name="BtnGetSites" 
                    Content="Fetch Site(s)" Height="32" Width="90"  Margin="3,0,10,10"
                        Click="BtnGetSitesClick1" HorizontalAlignment="Right" Grid.Column="1" />

                            <!--<ListBox Name="ListSites"  MaxHeight="300" Margin="10,0,10,10" BorderThickness="0">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <CheckBox IsChecked="{Binding IsSelected}" 
                                  Content="{Binding SitePath}"
                                 FontSize="14" Foreground="Black" Margin="5,5,5,5" ToolTip="{Binding SitePath}" />
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>-->
                            <TreeView Name="mainTree" ItemsSource="{Binding SiteViewModela}">
                                <TreeView.ItemContainerStyle>
                                    <Style TargetType="{x:Type TreeViewItem}">
                                        <Setter Property="IsExpanded" Value="True"/>
                                    </Style>
                                </TreeView.ItemContainerStyle>
                                <TreeView.ItemTemplate>
                                    <HierarchicalDataTemplate ItemsSource="{Binding Subsites}" DataType="{x:Type local:SiteViewModel}" >
                                        <CheckBox IsChecked="{Binding IsSelected}" IsEnabled="{Binding IsUserEnabled}" Content="{Binding SitePath}"  Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" ></CheckBox>
                                    </HierarchicalDataTemplate>
                                </TreeView.ItemTemplate>
                            </TreeView>                            
                            <TextBlock x:Name="txtDisclaimer" Text="Disclaimer: Duplicate sites will not be scanned." FontSize="10" />
                        </StackPanel>
                    </Expander>


                    <Expander Name="ExpanderRegEx" Margin="10,0,0,10" Header="Regular Expressions" FontSize="14" Expanded="Expander_OnExpanded">
                        <StackPanel>
                            <!--<TextBlock Text="Reg Ex" Margin="10"
                       FontSize="25" Foreground="Black" TextTrimming="None" 
                       TextWrapping="WrapWithOverflow"                        />-->
                            <TextBlock Text="You can provide custom pattern or select from known patterns" 
                       TextTrimming="None" Margin="10,10,10,10"
                       TextWrapping="WrapWithOverflow" 
                       />
                            <TextBlock Text="Custom RegEx" 
                      TextTrimming="None" Margin="10,00,10,5"
                       TextWrapping="WrapWithOverflow" 
                       />
                            <TextBox Name="TxtRegEx"  Height="30"   Margin="10,0,10,5" BorderThickness="0" VerticalContentAlignment="Center" />

                            <TextBlock Text="Known RegEx" 
                       TextTrimming="None" Margin="10,10,10,5"
                       TextWrapping="WrapWithOverflow" 
                       />
                            <ListBox Name="ListRegEx"  Margin="10,0,10,10" BorderThickness="0" MaxHeight="300">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">

                                            <CheckBox IsChecked="{Binding IsSelected}" Content="{Binding Pattern}"
                                  FontSize="14" Margin="5" Foreground="Black"  />
                                            <TextBlock Text=" - " Margin="5" FontSize="12" Foreground="Black"/>
                                            <TextBlock Text="{Binding Name}" Margin="5" FontSize="12" Foreground="Black"/>
                                        </StackPanel>

                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </Expander>

                    <Expander Name="ExpanderFileExt" Margin="10,0,0,10" Header="File Extensions to Scan" FontSize="14" Expanded="Expander_OnExpanded">
                        <StackPanel>

                            <ListBox Name="ComboFileExtension" Margin="10,0,10,10">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <CheckBox IsChecked="{Binding IsSelected}" Content="{Binding FileExtension}"
                                  FontSize="14" Margin="5" Foreground="Black"  />
                                            <TextBlock Text=" - " Margin="5" FontSize="12" Foreground="Black"/>
                                            <TextBlock Text="{Binding Name}" Margin="5" FontSize="12" Foreground="Black"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </Expander>

                    <Button Content="Start Scan" Margin="10" Height="40" Click="ButtonClickScan" HorizontalAlignment="Stretch"  />

                </StackPanel>

            </ScrollViewer>

            <ScrollViewer Grid.Column="1" Grid.Row="1" Grid.RowSpan="3">
                <TabControl  Name="ScanResultsTab">
                    <TabItem Header="Scan Summary">
                        <StackPanel>
                            <DataGrid Name="GDResults" ItemsSource="{Binding Results}"  VerticalAlignment="Stretch" BorderThickness="0" Margin="0,0,0,40"
                  CanUserReorderColumns="True" CanUserResizeColumns="True" Foreground="Black" 
          CanUserResizeRows="False" CanUserSortColumns="True" FontSize="14" Background="White" AutoGenerateColumns="False" IsReadOnly="True" >
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="Scan Summary Item" Binding="{Binding Path=Key }" Width="Auto" />
                                <DataGridTextColumn Header="Scan Summary Description" Binding="{Binding Path=Value}" Width="Auto"/>
                            </DataGrid.Columns>
                        </DataGrid>
                            <DataGrid Name="GDScanPatter" VerticalAlignment="Stretch" BorderThickness="0"
                  CanUserReorderColumns="True" CanUserResizeColumns="True" Foreground="Black" 
          CanUserResizeRows="False" CanUserSortColumns="True" FontSize="14" Background="White" AutoGenerateColumns="False" IsReadOnly="True" >
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Pattern" Binding="{Binding Path=Key}" Width="Auto" />
                                <DataGridTextColumn Header="# of Issues" Binding="{Binding Path=Value}" Width="Auto"/>
                            </DataGrid.Columns>
                        </DataGrid>
                        </StackPanel>
                    </TabItem>
                    <TabItem Header="Errors" Height="22" VerticalAlignment="Top">
                        <DataGrid Name="GDErrors" ItemsSource="{Binding Errors}" CanUserReorderColumns="True"  VerticalAlignment="Stretch" BorderThickness="0"
                 Foreground="Red" FontSize="14" Background="White" AutoGenerateColumns="False" >
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Message" Binding="{Binding Path=Message}" Width="Auto" />
                            </DataGrid.Columns>
                            <!--<DataGridTemplateColumn Visibility="Visible">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Message}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>-->
                        </DataGrid>
                    </TabItem>
                </TabControl>
            </ScrollViewer>


            <!--<StackPanel Background="DimGray" Grid.Column="1" Grid.Row="0">
            <TextBlock Text="Scan Results" Margin="10"
                       FontSize="25" Foreground="White" TextTrimming="None" 
                       TextWrapping="WrapWithOverflow"                        />       
        </StackPanel>-->

            <!--<StackPanel Background="White" Grid.Column="1" Grid.Row="2" >
                <Button Content="Export to Excel" Margin="10" Width="100" Height="40"  HorizontalAlignment="Right" 
                    Name="BtnExportXls" Click="BtnExportXlsClick1"/>
            </StackPanel>-->

        </Grid>
    </xctk:BusyIndicator>
</Window>
